import java.util.ArrayList;
import java.util.List;

/**
 * @author LKQ
 * @date 2022/1/8 10:12
 * @description 对称生成，借助或运算
 */
public class FormalSolution {
    public static void main(String[] args) {
        FormalSolution formalSolution = new FormalSolution();
        formalSolution.grayCode(2);
    }
    public List<Integer> grayCode(int n) {
        List<Integer> ret = new ArrayList<Integer>();
        ret.add(0);
        for (int i = 1; i <= n; i++) {
            int m = ret.size();
            for (int j = m - 1; j >= 0; j--) {
                ret.add(ret.get(j) | (1 << (i - 1)));
            }
        }
        return ret;
    }
}
